package Project4;

import java.util.*;

class PutStatement extends Statement{
	private String name;
	private Hashtable<String, Variable> vars;

	public PutStatement(String s, Hashtable<String, Variable> v){
		name = s;
		vars = v;
	}

	public String toString(){
		String r = "#-- PUT STATEMENT --\n";
		
		String type = vars.get(name).getType();
		if(type.equals("INT")){
			r += "li $v0, 1\n";
			r += "li $a0, " + vars.get(name).getOffset() + "\n";
			r += "add $a0, $s0, $a0\n";
			r += "lw $a0, ($a0)\n";
		}

		if(type.equals("REAL")){
			r += "li $v0, 2\n";
			r += "li $a0, " + vars.get(name).getOffset() + "\n";
			r += "add $a0, $s0, $a0\n";
			r += "lw $f12, ($a0)\n";
		}

		if(type.equals("STRING")){
			r += "#-- PUT STRING TODO --\n";
		}

		if(type.equals("BOOLEAN")){
			r += "#-- print true or false? --\n";
		}

		if(type.equals("VOID")){
			return "#-- printing a void variable? Very funny sir. --\n";
		}
		
		r += "syscall\n";
		r += "#-- END PUT --\n\n";
		return r;
	}
}
